﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace AgileToDo.Common
{
    [ValueConversion(typeof(DateTime?),typeof(bool?))]
    public class DateTime2BoolConverter : IValueConverter
    {

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            var dateTime = (DateTime?)value;

            bool? result = null;

            result = dateTime.HasValue;

            return result;

        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {

            var check = (bool?)value;

            DateTime? result = null;

            if(check.HasValue&&check.Value)
            {
                result = DateTime.Now;
            }

            return result;

        }

    }
}
